package view;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * The Class SGIClientGUI.
 * @author Tomer Elkayam
 */
public class SGIClientGUI extends JFrame{
	
	/** The lbl port. */
	private JLabel lblPort = null;
	
	/** The lbl host. */
	private JLabel lblHost = null;
	
	/** The txt host. */
	private JTextField txtHost = null;
	
	/** The txt port. */
	private JTextField txtPort = null;
	
	/** The btn ok. */
	private JButton btnOk = null;
	
	/** The btn cancel. */
	private JButton btnCancel = null;
	
	/**
	 * Instantiates a new SGI client gui.
	 */
	public SGIClientGUI() {
		getContentPane().setLayout(null);
		
		lblPort = new JLabel("Port");
		lblPort.setBounds(10, 40, 46, 14);
		getContentPane().add(lblPort);
		
		lblHost = new JLabel("Host");
		lblHost.setBounds(10, 11, 46, 14);
		getContentPane().add(lblHost);
		
		getContentPane().add(getTxtHost());
		getContentPane().add(getTxtPort());
		
		btnOk = new JButton("OK");
		btnOk.setBounds(23, 76, 89, 23);
		getContentPane().add(btnOk);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setBounds(122, 76, 89, 23);
		getContentPane().add(btnCancel);
		
		this.setTitle("Connection to Server");
		this.setBounds(500, 200, 245, 138);
		this.setVisible(true);
		this.setResizable(false);
	}
	
	/**
	 * Gets the txt host.
	 *
	 * @return the txt host
	 */
	private JTextField getTxtHost(){
		if(txtHost == null){
			txtHost = new JTextField();
			txtHost.setBounds(51, 9, 160, 20);
			txtHost.setColumns(10);
			txtHost.setText("10.0.0.15");
		}
		return txtHost;
	}

	/**
	 * Gets the txt port.
	 *
	 * @return the txt port
	 */
	private JTextField getTxtPort(){
		if(txtPort == null){
			txtPort = new JTextField();
			txtPort.setBounds(51, 37, 160, 20);
			txtPort.setColumns(10);
		}
		return txtPort;
	}
	
	/**
	 * Clear fields.
	 */
	public void clearFields(){
		txtHost.setText("");
		txtPort.setText("");
	}
	
	/**
	 * Gets the host.
	 *
	 * @return the host
	 */
	public String getHost(){
		return txtHost.getText();
	}
	
	/**
	 * Gets the port.
	 *
	 * @return the port
	 */
	public int getPort(){
		if(txtPort.getText().equals(""))
			return 0;
		return Integer.parseInt(txtPort.getText());
	}
	
	/**
	 * Adds the ok action listener.
	 *
	 * @param listener the listener
	 */
	public void addOKActionListener(ActionListener listener){
		btnOk.addActionListener(listener);
	}
	
	/**
	 * Adds the cancel action listener.
	 *
	 * @param listener the listener
	 */
	public void addCancelActionListener(ActionListener listener){
		btnCancel.addActionListener(listener);
	}
	
	/**
	 * Display wrn message.
	 *
	 * @param msg the msg
	 */
	public void displayWrnMessage(String msg)
	{
		JOptionPane.showMessageDialog(this, msg);
	}
	
}
